﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Forms.Reports;

namespace eTMS.Forms.Students
{
    public partial class FrmAskForPrintCapNhatData : eTMS.Controls.BaseForm
    {
        public FrmAskForPrintCapNhatData()
        {
            InitializeComponent();
        }
        private string _ColumnUpdate = "";
        public string ColumnUpdate
        {
            set
            {
                _ColumnUpdate = value;
            }
        }
        private string _ReportName = "";
        public string ReportName
        {
            set
            {
                _ReportName = value;
            }
        }
        private string _ColName = "";
        public string ColName
        {
            set
            {
                _ColName = value;
            }
        }
        private DataTable tblData = new DataTable();
        public void SetDataSource(DataTable table)
        {
            tblData = table;
            tblData.DefaultView.RowFilter = "";
        }
        private DataTable tblDataLookUp = new DataTable();
        public void SetDataSourceLookUp(DataTable table, string Display, string Value)
        {
            tblDataLookUp = table;
            listView1.CheckBoxes=true;
            foreach (DataRow row in tblDataLookUp.Rows)
            {
                ListViewItem item = new ListViewItem();
                item.Text = row[Display].ToString();
                item.Tag = row[Value];
                listView1.Items.Add(item);
                item.Checked = true;
            }
        }
        private void ucCommandDialog1_OnOK(object sender, CancelEventArgs e)
        {
            Reports.FrmHtmlReportView frmHtmlReportView = new FrmHtmlReportView();
            frmHtmlReportView.AddReportParameter("TENREPPORT", _ReportName);
            frmHtmlReportView.AddReportParameter("TENCOT", _ReportName);
            List<string> ls = new List<string>();
            foreach (ListViewItem item in listView1.CheckedItems)
            {
                ls.Add(item.Tag.ToString());
            }
            if (ls.Count > 0)
            {
                tblData.DefaultView.RowFilter = _ColumnUpdate + " IN("+string.Join(",",ls.ToArray())+")";
                tblData = tblData.DefaultView.ToTable();
            }
            frmHtmlReportView.SetDataSource(tblData, "13_DanhSachUpDateCommon.htm");
            frmHtmlReportView.ShowDialog();
        }
    }
}
